<script type='text/javascript'>
var media_type = 'mv';
var play_index = 0;
var url_array = [ {volist name="$info.mv_url" id="rs"} decodeURIComponent('{:str_replace('.','x@01x@01',urlencode(fun("player@get_iframe_url",$rs.url)))}'.replace(/x@01x@01/g,".")).replace(/\+/g," "), {/volist} ];

//切换到哪一集
function change_play(index,obj){
	play_index = index;
	layer.msg("请稍候,视频加载中...");
	
	$("#player_warp").show(); //避免试看的隐藏掉,导致一直隐藏
	if(typeof(Dplayer1)=='object'){
		Dplayer1.switchVideo({
			url: url_array[index],
			pic: '{$webdb.video_player_bgpic}',
			thumbnails: '{$webdb.video_player_bgpic}',
		});
		Dplayer1.on('canplay', function () {
			Dplayer1.play();
		});
	}else if(typeof(player1)=='object'){
		player1.newVideo({autoplay:true,video:url_array[index]});
	}else{
		have_playtime = 0;
		$('.player_1').attr('src',url_array[index]);
	}	
	$(".more_list a").removeClass('choose');
	obj.addClass('choose');
}





//Ckplay监听播放器状态,这个函数会被播放器自动加载执行
function loadedHandler1(){

	play_url();	//URL指定播放哪辑

	player1.addListener('loadedmetadata', function(){	//视频加载成功
		player1.videoPlay();	//自动播放		
//		setTimeout(function(){
//			play_log(play_index);	//播放记录
//		}, 3000 );

		if(typeof(api_player_ready)=='function'){
			api_player_ready();
		}
	});

	player1.addListener('error', function(time){
		if(typeof(api_player_error)=='function'){
			api_player_error();
		}
	});

	player1.addListener('play', function(time){
		if(typeof(api_player_play)=='function'){
			api_player_play();
		}
	});

	player1.addListener('pause', function(time){
		if(typeof(api_player_pause)=='function'){
			api_player_pause();
		}
	});

	player1.addListener('time', function(time){		//视频已播放多少时间
		time = parseInt(time);
		console.log('error:'+time);
		//if(url_money[play_index]>0 && time>10){	//只能试看10秒
		//	player1.videoPause();
		//	layer.confirm("需要支付 "+url_money[play_index]+" 元,才能继续播放,你还要继续吗?",{btn:['继续','放弃']},function(){
		//		pay_money(url_money[play_index],play_index)
		//	});
		//}

		if(typeof(api_player_time)=='function'){
			api_player_time(time);
		}

	});

	player1.addListener('ended', function(){	//当前播放完毕,播放下一个
		play_index++;
		if(typeof(url_array[play_index])!='undefined'){
			change_play(play_index,$(".more_list a").eq(play_index));
		}else{
			var url = "{:fun('content@next_url',$info,'list')}";
			if(url!=""){
				window.location.href = url+"#miao";
			}else{
				layer.alert("全部播放完毕了!");
			}
		}
		
		if(typeof(api_player_ended)=='function'){
			api_player_ended();
		}

	});
}

//收费试看结束要自动停止播放
function player_stop(){
	if(typeof(Dplayer1)=='object'){
		Dplayer1.pause();
	}else if(typeof(player1)=='object'){
		player1.videoPause();
	}	
}

function player_start(){
	if(typeof(Dplayer1)=='object'){
		Dplayer1.play(); //Dplayer1.toggle();
	}else if(typeof(player1)=='object'){
		player1.videoPlay();
	}else{
		$('.player_1').attr('src',url_array[play_index]);
	}	
}


//检查是否需要付费
var have_playtime = 0;
$(function(){

	if(typeof(Dplayer1)=='object'){ //监听事件
		Dplayer1.on('canplay', function () {
			Dplayer1.play();
			if(typeof(api_player_ready)=='function'){
				api_player_ready();
			}
		});
		Dplayer1.on('canplay', function () {
			Dplayer1.play();
			if(typeof(api_player_ready)=='function'){
				api_player_ready();
			}
		});
		Dplayer1.on('timeupdate', function () {
			api_player_time( parseInt(Dplayer1.video.currentTime) )
		});
		Dplayer1.on('error', function () {
			if(typeof(api_player_error)=='function'){
				api_player_error();
			}
		});
		Dplayer1.on('play', function () {
			if(typeof(api_player_play)=='function'){
				api_player_play();
			}
		});
		Dplayer1.on('pause', function () {
			if(typeof(api_player_pause)=='function'){
				api_player_pause();
			}
		});
		Dplayer1.on('ended', function () {
			play_index++;
			if(typeof(url_array[play_index])!='undefined'){
				change_play(play_index,$(".more_list a").eq(play_index));
			}else{
				var url = "{:fun('content@next_url',$info,'list')}";
				if(url!=""){
					window.location.href = url+"#miao";
				}else{
					layer.alert("全部播放完毕了!");
				}
			}			
			if(typeof(api_player_ended)=='function'){
				api_player_ended();
			}
		});
	}

	play_url();
	if($('.player_1').length==1){	//站外视频收费处理
		window.setInterval(function(){
			//console.log(have_playtime+'-index-'+play_index);
			if(url_money[play_index]>0 && have_playtime==10){	//只能试看10秒
				$('.player_1').attr('src','about:black');
				layer.confirm("需要支付 "+url_money[play_index]+" 元,才能继续播放,你还要继续吗?",{btn:['继续','放弃'],title:false,cancel:function(){}},function(){
					pay_money(url_money[play_index],play_index)
				},function(){});
			}
			play_log(play_index,have_playtime);		//播放记录
			have_playtime++;
		},1000);
	}
});



</script>